//
//  AppDelegate.m
//  UIhomework_14
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "AppDelegate.h"
#import "RootViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FourthViewController.h"
#import "DataBaseHandle.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
   
    
    //第一个
    RootViewController *rootVC = [[RootViewController alloc] init];
    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:rootVC];
    UIImage *image1 = [UIImage imageNamed:@"activity.png"];
    nav1.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"活动" image:image1 tag:1000] autorelease];
    
    //第二个
    SecondViewController *secVC = [[SecondViewController alloc] init];
    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:secVC];
    UIImage *image2 = [UIImage imageNamed:@"movie.png"];
    nav2.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"电影" image:image2 tag:1001] autorelease];
    
    //第三个
    ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
    UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:thirdVC];
    UIImage *image3 = [UIImage imageNamed:@"cinema.png"];
    nav3.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"影院" image:image3 tag:1002] autorelease];
    
    //第四个
    FourthViewController *fourVC = [[FourthViewController alloc] init];
    UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:fourVC];
    UIImage *image4 = [UIImage imageNamed:@"user.png"];
    nav4.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"用户" image:image4 tag:1003] autorelease];
    
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    NSArray *navVCS = [NSArray arrayWithObjects:nav1, nav2, nav3, nav4, nil];
    tabBarController.viewControllers = navVCS;
    _window.rootViewController = tabBarController;
    
    [rootVC release];
    [nav1 release];
    [secVC release];
    [nav2 release];
    [thirdVC release];
    [nav3 release];
    [nav4 release];
    [fourVC release];
    [tabBarController release];
    [_window release];
    
    
    //打开数据库
    [[DataBaseHandle shareDataBaseHandle] openDB];
    
    //创建电影表格
    [[DataBaseHandle shareDataBaseHandle] createMovieTable];
    
    //创建注册表格
    [[DataBaseHandle shareDataBaseHandle] createRegister];
    
    
    
    
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
